package com.jyh.controller;

import com.jyh.entity.User;
import com.jyh.service.UserService;
import jdk.nashorn.internal.ir.ReturnNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @author JYH
 * @version 1.0
 * @date 2022/12/7 13:48
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/{uid}")
    public User findById(@PathVariable Integer uid){
        User user = userService.findByUid(uid);
        return user;
    }
    @PostMapping
    public User save(@RequestBody User user){
        User user1 = userService.save(user);
        return user1;
    }
    @DeleteMapping("/{uid}")
    public int deleteByUid(@PathVariable Integer uid){
        int i = userService.deleteByUid(uid);
        return i;
    }
    @PutMapping
    public User updateByUid(@RequestBody User user){
        User user1 = userService.updateByUid(user);
        return user1;
    }
}
